/**
 * 出库单相关路由
 */
const express = require('express');
const router = express.Router();
const stockOutController = require('../controllers/stockOutController');
const { authenticate, authorize } = require('../middlewares/auth');
const { authMiddleware } = require('../middleware/auth');

// 获取出库单列表
router.get('/', authenticate, stockOutController.getStockOutOrders);

// 获取出库单详情
router.get('/:id', authenticate, stockOutController.getStockOutOrderById);

// 创建出库单
router.post('/', authenticate, authorize(['admin', 'manager']), stockOutController.createStockOutOrder);

// 更新出库单
router.put('/:id', authenticate, authorize(['admin', 'manager']), stockOutController.updateStockOutOrder);

// 删除出库单
router.delete('/:id', authenticate, authorize(['admin']), stockOutController.deleteStockOutOrder);

// 确认出库单
router.post('/:id/confirm', authenticate, authorize(['admin', 'manager']), stockOutController.confirmStockOutOrder);

// 取消出库单
router.post('/:id/cancel', authenticate, authorize(['admin', 'manager']), stockOutController.cancelStockOutOrder);

// 出库单明细相关路由
router.post('/:id/items', authenticate, authorize(['admin', 'manager']), stockOutController.addStockOutItem);
router.put('/:id/items/:itemId', authenticate, authorize(['admin', 'manager']), stockOutController.updateStockOutItem);
router.delete('/:id/items/:itemId', authenticate, authorize(['admin', 'manager']), stockOutController.deleteStockOutItem);

router.use(authMiddleware);

module.exports = router; 